﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Cinema : System.Web.UI.Page
{
    Tickets tk = new Tickets();
    public string Status(object obj)     
    {
        if(0==int.Parse(obj.ToString()))
        {
            return "Active";
        }
        else
        {
            return "Under repair";
        }
        
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(this.IsPostBack==false)
        {
            txtCinemaD.Text = tk.GetCinemaID();
            grvData.DataSource = tk.LoadCinema();
            grvData.DataBind();
        }
    }
    protected void grvDataCancel(object sender, GridViewCancelEditEventArgs e)
    {
        grvData.EditIndex = -1;
        grvData.DataSource = tk.LoadCinema();
        grvData.DataBind();

    }
    protected void grvDataEdit(object sender, GridViewEditEventArgs e)
    {
        grvData.EditIndex = e.NewEditIndex;
        grvData.DataSource = tk.LoadCinema();
        grvData.DataBind();
    }
    protected void grvDataUpload(object sender, GridViewUpdateEventArgs e)
    {
        if (tk.UpdateCinema(grvData.DataKeys[e.RowIndex].Value.ToString(),(grvData.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text, int.Parse((grvData.Rows[e.RowIndex].Cells[1].Controls[0] as DropDownList).SelectedValue.ToString())))
        {
            grvData.DataSource = tk.LoadCinema();
            grvData.DataBind();
        }
    }
    protected void btnSummit_Click(object sender, EventArgs e)
    {
        if(tk.AddCinema(tk.GetCinemaID(),txtCinemaName.Text,int.Parse(ddlStatus.SelectedValue.ToString())))
        {
            txtCinemaD.Text = tk.GetCinemaID();
            txtCinemaName.Text = null;
            ddlStatus.SelectedIndex = 0;
            grvData.DataSource = tk.LoadCinema();
            grvData.DataBind();
        }
    }
    protected void btnSearch0_Click(object sender, EventArgs e)
    {
        if ("" != txtSearch.Text.Trim())
        {
            grvData.DataSource = tk.GetCinemaByName(txtSearch.Text);
            grvData.DataBind();
        }
        else
        {
            lblError1.Visible = true;
            lblError1.Text = "Enter Cinema name !";
        }
    }
    protected void grvData_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        grvData.PageIndex = e.NewPageIndex;
        grvData.DataSource = tk.LoadCinema();
        grvData.DataBind();
    }
}